//
//  MusicTableViewCell.m
//  NuwaRobot
//
//  Created by Kendama on 2017/12/6.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "MusicTableViewCell.h"

@implementation MusicTableViewCell

- (void)didClickButton
{
    if (self.playBlock)
    {
        self.playBlock();
    }
}

- (void)setCountWithString:(NSString *)count
{
    [self.countButton setTitle:count forState:UIControlStateNormal];
    [self.countButton setImage:imageWithName(@"icon_value") forState:UIControlStateNormal];
    [self.countButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
}

- (void)setDateWithString:(NSString *)date
{
    [self.dateButton setTitle:date forState:UIControlStateNormal];
    [self.dateButton setImage:imageWithName(@"icon_duration") forState:UIControlStateNormal];
    [self.dateButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
}

- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        UIView *superView = self.contentView;
        _iconImageView = [[UIImageView alloc]init];
        [superView addSubview:_iconImageView];
    }
    return _iconImageView;
}
- (UILabel *)titleLabel
{
    if(!_titleLabel)
    {
        UIView *superView = self.contentView;
        _titleLabel = [[UILabel alloc]init];
        [superView addSubview:_titleLabel];
        [_titleLabel setFont:fontCommonSize];
        [_titleLabel setTextColor:[UIColor whiteColor]];
    }
    return _titleLabel;
}
- (UIButton *)playButton
{
    if(!_playButton)
    {
        UIView *superView = self.contentView;
        _playButton = [[UIButton alloc]init];
        [superView addSubview:_playButton];
        [_playButton setImage:imageWithName(@"icon_play") forState:UIControlStateNormal];
        [_playButton setImage:imageWithName(@"icon_pause") forState:UIControlStateSelected];
        [_playButton addTarget:self action:@selector(didClickButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _playButton;
}
- (UIButton *)countButton
{
    if(!_countButton)
    {
        UIView *superView = self.contentView;
        _countButton = [[UIButton alloc]init];
        [superView addSubview:_countButton];
        [_countButton.titleLabel setFont:fontCommonSize];
        [_countButton setTitleColor:rgba(212,212,212,1) forState:UIControlStateNormal];

    }
    return _countButton;
}
- (UIButton *)dateButton
{
    if(!_dateButton)
    {
        UIView *superView = self.contentView;
        _dateButton = [[UIButton alloc]init];
        [superView addSubview:_dateButton];
        [_dateButton.titleLabel setFont:fontCommonSize];
        [_dateButton setTitleColor:rgba(212,212,212,1) forState:UIControlStateNormal];

    }
    return _dateButton;
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self.contentView;
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(30));
        make.height.width.mas_equalTo(px1920Height(170));
    }];
    
    
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.right.mas_equalTo(superView.mas_right).with.offset(-px1080Width(57));
        make.height.width.mas_equalTo(px1920Height(80));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_iconImageView.mas_top);
        make.left.mas_equalTo(_iconImageView.mas_right).with.offset(px1080Width(43));
        make.right.mas_equalTo(_playButton.mas_left);
    }];
    
    [self.countButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_titleLabel.mas_left);
        make.bottom.mas_equalTo(_iconImageView.mas_bottom);
        make.width.mas_equalTo(80);
    }];
    
    [self.dateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_countButton.mas_right).with.offset(px1080Width(30));
        make.bottom.mas_equalTo(_countButton.mas_bottom);
        make.width.mas_equalTo(80);
    }];
    
    self.backgroundColor = [UIColor clearColor];
    superView.backgroundColor = rgba(27,44,81,1);
    superView.layer.cornerRadius = 3;
}


@end
